package operation;

import student.Student;
import student.StudentArray;

import java.util.Scanner;

/*
 1. 能检查对相同的学号进行检查 ---> 要对Student的类进行 compare的导包 并且完成compareto的方法
 2. 如果一开始的满了 可以完成动态扩容
 3.
 */
public class AddOperation implements IOperation {
    @Override
    public void work(StudentArray stulist) {
        System.out.println("增加学生信息");
        int sz = stulist.getUsedSize();
        if(stulist.getMAX_SIZE() == sz){
            System.out.println("准备扩容");
            if(stulist.Dilatation()){
                System.out.println("扩容成功");
            } else {
                System.out.println("扩容失败");
                return;
            }
        }
        //扩容/没扩容 来进行学习消息的录入
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名");
        String name = sc.nextLine();
        System.out.println("请输入性别");
        String sex = sc.nextLine();
        System.out.println("请输入身份证");
        String id = sc.nextLine();
        System.out.println("请输入电话");
        String tele = sc.nextLine();
        System.out.println("请输入学号");
        int studentId = sc.nextInt();
        System.out.println("请输入年龄");
        int age = sc.nextInt();
        // new Student的对象 来存放 上面刚录入的信息
        Student stu = new Student(studentId,name,age,sex,id,tele);
        for (int i = 0; i < sz; i++) {
            Student stu1 = stulist.getStudent(i);
            if(stu1.getStudentId() == studentId) {
                System.out.println("已经有该学生，不能进行放入");
                return;
            }
        }
        stulist.setStudent(sz,stu);
        stulist.setUsedSize(sz+1);
        System.out.println("插入成功");

    }
}

